#include "MySqlParserBaseVisitor.h"
#include "antlr4-runtime.h"
#include <string>

using namespace antlrcpptest;

//map传入antlrcp::Any类似boost::any可以使用任意类型
// typedef std::map<std::string, antlrcpp::Any> MAP_STRING_T;

typedef struct ta{
    std::string name;
    std::string column;
}ta;

class from_ds
{   // or private 
    public:
        int flag;
        ta column1; ta column2;
    public:
        void change_f(int s) { flag = s; }
        void change_t(ta a,ta b){ 
            column1.name = a.name; column1.column = a.column; 
            column2.name = b.name; column2.column = b.column;
        }
        void test() { std::cout << flag << std::endl;  std::cout << column1.name + column1.column << std::endl; 
                    std::cout << column2.name + column2.column << std::endl;
        }
        int eq() { // judge whether in one party
            int x = 1;
            if (column1.name == column2.name )
                x = 0; 
            return x;
            }
};

class group_ds
{   
    // or private 
    public:
        int flag ;
        ta co; 
    public:
        void change_f(int s) { flag = s; }
        void change_t(ta a){ co.name = a.name; co.column = a.column; }
        void test() { std::cout << flag << std::endl;  std::cout << co.name + co.column << std::endl; }
};

class select_ds
{   // or private 
    public:
        int flag ;
        ta co;
    public:
        void change_f(int a) { flag = a; }
        void change_t(ta b){ co.name = b.name; co.column = b.column; }
        void test() {   std::cout << co.name + co.column << std::endl; }
};

class exe_state
{   // or private 
     public:
         int plan ; // psi pcsi
         std::string table[2]; // table
         
     public:
         void decide(select_ds* s,from_ds* f,std::vector<group_ds*> g){
             if ( f->flag == 0){ 
                std::cout << f->column1.name + "local compute , not considered" << std::endl;
             } else {
                if( s->flag == 1 )
                    std::cout << f->column1.name + f->column2.name + " compute togther PCSI-sum:" ;
                else if( s->flag == 2 )
                    std::cout << f->column1.name + f->column2.name + " compute togther PCSI-AVG:" ;
                else if( s->flag == 3 )
                    std::cout << f->column1.name + f->column2.name + " compute togther PCSI-COUNT:" ;
                else std::cout << f->column1.name + f->column2.name + " compute togther PSI:" ;
                s -> test();
             }
            if( g[0] -> flag == 0)
                std::cout << "no group and restor protocl" << std::endl;
            else std::cout << "need to group" << std::endl;

            return ;
         }
};



class ExeVisitor : public MySqlParserBaseVisitor
{
    private:
        // select_ds* var_s;
        // from_ds* var_f;
        // group_ds* var_g;
        exe_state* var_exe;

    public:
        ExeVisitor();
        ~ExeVisitor();

        virtual antlrcpp::Any visitQuerySpecification(MySqlParser::QuerySpecificationContext *ctx) override;
        virtual antlrcpp::Any visitSelectElements(MySqlParser::SelectElementsContext *ctx) override;
        virtual antlrcpp::Any visitFromClause(MySqlParser::FromClauseContext *ctx) override;
        virtual antlrcpp::Any visitGroupByClause(MySqlParser::GroupByClauseContext *ctx) override;
        virtual antlrcpp::Any visitAggregateWindowedFunction(MySqlParser::AggregateWindowedFunctionContext *ctx) override;
        virtual antlrcpp::Any visitAggregateFunctionCall(MySqlParser::AggregateFunctionCallContext *ctx) override;
        virtual antlrcpp::Any visitSimpleId(MySqlParser::SimpleIdContext *ctx) override;
        virtual antlrcpp::Any visitDottedId(MySqlParser::DottedIdContext *ctx) override;
        virtual antlrcpp::Any visitInnerJoin(MySqlParser::InnerJoinContext *ctx) override;
        virtual antlrcpp::Any visitFullColumnName(MySqlParser::FullColumnNameContext *ctx) override;
        virtual antlrcpp::Any visitTableSourceBase(MySqlParser::TableSourceBaseContext *ctx) override;
        virtual antlrcpp::Any visitBinaryComparisonPredicate(MySqlParser::BinaryComparisonPredicateContext *ctx) override;
};